package com.fresh.controller;

import com.alibaba.fastjson.JSONObject;
import com.fresh.common.ResponseResult;
import com.fresh.entity.User;
import com.fresh.service.VerifyService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import com.fresh.qo.UserQO;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;

@RestController
@RequestMapping("/user")
public class VerifyController {


    @Autowired
    private VerifyService verifyService;


    @PostMapping("/verify")
    public ResponseResult verifyIdCard(HttpServletRequest request,@RequestBody UserQO userQO){
        String s = verifyService.verifyIdCard(userQO);
        JSONObject json = JSONObject.parseObject(s);
        if ("10000".equals(json.get("code"))){
            User user = new User();
            //TODO        String userId = request.getHeader("userId");
//            user.setUserId(Integer.parseInt(request.getHeader("userId")));
            user.setUserId(1);
            user.setName(userQO.getName());
            user.setIdCard(userQO.getIdCard());
            verifyService.updateIdCard(user);
            return ResponseResult.success(json);
        }else {
            return ResponseResult.error(500,json.get("message").toString());
        }
    }


}
